<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen,fancybox'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <input type="hidden" readonly id="productMember" name="productMember"  class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <input type="text" id="supplierName" name="supplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">柜号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="createPlanNo" name="createPlanNo" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select id="billStatus" name="billStatus" class="form-control">
                                <option value="">全部分类</option>
                                <option value="0" >待审核</option>
                                <option value="1" >审核中</option>
                                <option value="2" >审核通过</option>
                                <option value="3" >已拒绝</option>
                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>

            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
            </div>
            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/finance/bill/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="billRemark" name="billRemark" value="" class="form-control">
                </div>
                <div id="id" hidden="hidden" name="id"></div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload,imgbox'}){}%>
<script>


    var $relatedTable = $('#relatedTable');
    $(function(){
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '供应商',
                    field: 'supplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '不含税金额',
                    field: 'billPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '税额',
                    field: 'billTax',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '含税金额',
                    field: 'billMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票号码',
                    field: 'billNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票代码',
                    field: 'billCode',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票图片',
                    field: 'billImg',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            return '<a class="fancybox" href="'+v+'"><img src="' + v + '" style="width:80px;height:60px;"/></a>';;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '状态',
                    field: 'billStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 0:
                                result='待审核';
                                break;
                            case 1:
                                result='审核中';
                                break;
                            case 3:
                                result='已拒绝';
                                break;
                            case 2:
                                result='审核通过';
                                break;

                            default:
                                result='';
                        }
                        return result;
                    }
                },
                {
                    title: '备注',
                    field: 'billRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //修改按钮
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/supply/bill/editPage.do?id='+id, 'yes']
                    });
                });

                $('.btn-send').on('click',function(){
                    var id = $(this).attr('data-val')
                    layer.confirm('确定要审核通过当前数据？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/bill/usave.do',{id: id,billStatus:2},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                    layer.closeAll();
                                });
                            }else{
                                layer.closeAll(); //关闭弹窗
                                layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                                        layer.closeAll();
                                    }});
                            }
                        });
                    });
                });

                $('.del-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $('#id').val(id);
                    layer.open({
                        type:1,
                        title:'退回原因',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });
            }
        });

        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/finance/bill/findByCnd?'+$('#search-form').serialize() });
        });

        //操作菜单
        function optFormatter(value,row){
            var content= '';
            if(row.billStatus==1) {
                content += '<button class="btn-send btn btn-xs btn-success" data-val="' + row.id + '" title="审核通过">  审核通过</button>';
                content += '<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i> 退回</button>';
            }
            return content;
        }
    });

    //提交表单
    $('.save-btn').on('click',function(){
        var id=$("#id").val();
        //清关计划
        layer.confirm('确定要修改当前计划？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/bill/usave.do',{id:id,billStatus:3,billRemark:$("#billRemark").val()},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/finance/bill/export?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
